/*
 * Factualy.java
 *
 * Created on August 30, 2008, 5:23 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author haolt_c0708l
 */
public class Factualy {
    /** Creates a new instance of Factualy */

    private int FactualyID;
    private String FactualyName;

    /**
     *get FactualyID
     *@return String FactualyID
     */
    public int getFactualyID() {
        return FactualyID;
    }

    /**
     *ser value for FactualyID field
     *@param FactualyID
     */
    public void setFactualyID(int FactualyID) {
        this.FactualyID = FactualyID;
    }

    /**
     *get Factualy Name
     *@return String
     */
    public String getFactualyName() {
        return FactualyName;
    }

    /**
     *set value for FactualyName
     *@param FactualyName
     */
    public void setFactualyName(String FactualyName) {
        this.FactualyName = FactualyName;
    }

    /**
     *get all Factualy in Hospital
     *@return Vector
     */
    public static Vector getAllFactualys() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllFactualys");
            while(rs.next()){
                Factualy f = new Factualy();
                f.setFactualyID(rs.getInt(1));
                f.setFactualyName(rs.getString(2));
                v.add(f);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }   
    
    /**
     *search Factualy by ID
     *@param id
     *@return Vector
     */
    public static Vector getFactualyById(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchById", paramList);
            
            while(rs.next()){
                Factualy f = new Factualy();
                f.setFactualyID(rs.getInt(1));
                f.setFactualyName(rs.getString(2));
                v.add(f);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     
    

    /**
     *inserst into Factualy's table once record
     *@param f
     *@return int
     */
    public static int insertFactualy(Factualy f) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(f.FactualyName);
        i=DBHelper.executeUpdate("spInsertFactualy",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }        

    /**
     *update into Factualy's table once record
     *@param id
     *@param f
     *@return int
     */    
    public static int updateFactualy(int id, Factualy f) throws SQLException
    {
        int i;
        try{
           Vector paramList = new Vector();
           paramList.add((Integer)id);
           paramList.add(f.FactualyName);
           i=DBHelper.executeUpdate("spupdateFactualyById",paramList);
        }catch(SQLException e)
        {
          throw e;
        }
        return i;
    }      
}
